package org.agony2d.gpu {
	import flash.display.BitmapData;
	import flash.geom.Rectangle;
	import org.agony2d.gpu.core.AAManager;
	import org.agony2d.gpu.core.WorldAA;
	import org.agony2d.gpu.supportClasses.textures.TextureManager;
	import org.agony2d.core.agony_internal;
	import org.agony2d.core.ProcessManager;
	import org.agony2d.debug.Logger;
	
	use namespace agony_internal;
	
	[Event(name = "beginning", type = "org.agony2d.notify.AEvent")]
	
	[Event(name = "reset",     type = "org.agony2d.notify.AEvent")] 
	
	/** [ AgonyAA ]...(Agony Accelerated App)
	 *  [◆]
	 *  	1.  enableErrorChecking
	 *  	2.  paused
	 *  [◆◆]
	 *  	1.  startup
	 *  	2.  addFullTexture
	 *  	3.  addRegionTexture
	 *  	4.  removeTexture
	 *  	5.  createWorld
	 *  	6.  getWorldAt
	 *  [★]
	 *  	a.  2d平台型
	 *  	b.  2d纵版射击
	 *  	c.  2d解谜益智
	 *  	d.  2d-ARPG
	 *  [★]
	 *  	1.  ImageAA × TintedImage × DrawableImage(??)
	 *  	2.  Animator(??)
	 *  	3.  FusionAA × TextAA
	 *  	4.  AloneGroupAA × StateGroupAA × BatchGroupAA
	 */
public class AgonyAA {
	
	public static function get enableErrorChecking() : Boolean {	
		return AAManager.g_enableErrorChecking
	}
	
	public static function set enableErrorChecking( b:Boolean ) : void {
		AAManager.enableErrorChecking = b
	}
	
	public static function get paused() : Boolean {
		return AAManager.g_paused
	}
	
	public static function set paused( b:Boolean ) : void {
		if (AAManager.g_paused != b) {
			AAManager.g_paused = b
			Logger.reportMessage("AgonyAA", (b ? '▼' : '▲') + ' paused [ ' + b + ' ]...')
		}
	}
	
	public static function startup( bgColor:uint,
									hasMaskForAspectRatio:Boolean = false,
									antiAlias:int = 0,
									profile:String = "baselineConstrained", 
									maxNodeDepth:int = 8,
									stage3dIndex:int = 0 ) : void {
		if (!ProcessManager.g_stage) {
			Logger.reportError("AgonyAA", "startup", "AgonyCore has not started up...!!");
		}
		else if (AAManager.g_stage3d) {
			Logger.reportError("AgonyAA", "startup", "AgonyAA has been started up...!!")
		}
		AAManager.g_stage = ProcessManager.g_stage
		g_AA.startup(bgColor, hasMaskForAspectRatio, antiAlias, profile, maxNodeDepth, stage3dIndex)
	}
	
	public static function addFullTexture( name:String, data:BitmapData, mipmapEnabled:Boolean = false, optimizeForRenderToTexture:Boolean = false ) : void {
		TextureManager.addFullTexture(name, data, mipmapEnabled, optimizeForRenderToTexture)
	}
	
	public static function addRegionTexture( fullTextureName:String, regionName:String, regionRect:Rectangle ) : void {
		TextureManager.addRegionTexture(fullTextureName, regionName, regionRect)
	}
	
	public static function removeTexture( fullTextureName:String ) : void {
		TextureManager.removeTexture(fullTextureName)
	}
	
	public static function createWorld( width:int = -1, height:int = -1, invalidWhenLeave:Boolean = false, worldName:String = null ) : WorldAA {
		return g_AA.createWorld(width, height, invalidWhenLeave)
	}
	
	public static function getWorldAt( index:int ) : WorldAA {
		return g_AA.getWorldAt(index)
	}
	
	public static function addEventListener( type:String, listener:Function, priority:int = 0 ) : void {
		g_AA.addEventListener(type, listener, priority)
	}
	
	public static function removeEventListener( type:String, listener:Function ) : void {
		g_AA.removeEventListener(type, listener)
	}
	
	
	private static var g_AA:AAManager = new AAManager
}
}